<?php

class Application_Model_Report {
	
	protected $_db_table_report;
	
	public function __construct() {
		
		$config = array(
			"name" => "Report",
			"primary" => array(
				"user_email",
				"upload_datetime"
			)
		);
		$this->_db_table_report = new Zend_Db_Table($config);
		
	}
	
	public function insertReport(
		$user_email, 
		$report_datetime, 
		$message, 
		$species, 
		$latitude, 
		$longitude) {
		
		$upload_datetime = new Zend_Date();
		$upload_datetime = $upload_datetime->toString(DATETIME_FORMAT);
		
		$data = array(
			"user_email" => $user_email,
			"upload_datetime" => $upload_datetime,
			"report_datetime" => $report_datetime,
			"message" => $message,
			"species" => $species,
			"latitude" => $latitude,
			"longitude" => $longitude
		);
		
		try {
			$this->_db_table_report->insert($data);
		} catch (Exception $e) {
			return false;
		}
		
		return true;
		
	}
	
	public function getReportsOfSpecies($species) {
		
		$where = $this->_db_table_report->select();
		$where->where("species = ?", $species);
		$result = $this->_db_table_report->fetchAll($where);
		$result = $result->toArray();
		
		
	}
	
}